//
//  MainPageGoodsCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/14.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "MainPageGoodsCell.h"

@interface MainPageGoodsCell()

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UIImageView *goodsImgV;//商品图片

@property (nonatomic,strong) UILabel *goodsInfoLB;//商品介绍lb

@property (nonatomic,strong) UILabel *goodsPriceLB;//商品价格lb

@property (nonatomic,strong) UIImageView *goodsSourceImgV;//商品来源图片

@property (nonatomic,strong) UILabel *goodsSourceLB;//商品来源lb

@end

@implementation MainPageGoodsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = Color_Clear;
        self.contentView.backgroundColor = Color_Clear;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(MainPageGoodsModel *)model{
    _model = model;
    
    self.goodsSourceLB.text = _model.company;
    self.goodsInfoLB.text = _model.name;
    self.goodsPriceLB.text = [NSString stringWithFormat:@"%ldTB",_model.mintbprice];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.goodsImgV sd_setImageWithURL:[NSURL URLWithString:model.listpic] placeholderImage:LoadImage(@"")];
        [self.goodsSourceImgV sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:LoadImage(@"首页_商店图标1")];
    });
}

#pragma mark - UI

-(void)initUI{
    
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.goodsImgV];
    [self.bgView addSubview:self.goodsInfoLB];
    [self.bgView addSubview:self.goodsPriceLB];
    [self.bgView addSubview:self.goodsSourceImgV];
    [self.bgView addSubview:self.goodsSourceLB];
    
}

#pragma mark - lazy
-(UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(14, 0, ScreenWidth-18-10, 160*Width_Scale)];
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 8;
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
//商品图片
-(UIImageView *)goodsImgV{
    if (!_goodsImgV) {
        _goodsImgV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 20*Width_Scale, 120*Width_Scale, 120*Width_Scale)];
        _goodsImgV.image = LoadImage(@"首页_商品占位图1");
    }
    return _goodsImgV;
}
//商品信息简介lb
-(UILabel *)goodsInfoLB{
    if (!_goodsInfoLB) {
        _goodsInfoLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+16, self.goodsImgV.top, (ScreenWidth - 60 - 120*Width_Scale), 40)];
        _goodsInfoLB.numberOfLines = 2;
        _goodsInfoLB.textAlignment = NSTextAlignmentLeft;
        _goodsInfoLB.textColor = RGB(51, 51, 51);
        _goodsInfoLB.text = @"Apple Watch Series 3 银色铝金属表壳边框";
        _goodsInfoLB.font = FontSet(15);
    }
    return _goodsInfoLB;
}
//商品价格lb
-(UILabel *)goodsPriceLB{
    if (!_goodsPriceLB) {
        _goodsPriceLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+16, self.goodsInfoLB.bottom+13, (ScreenWidth - 60 - 120*Width_Scale), 25)];
        _goodsPriceLB.textAlignment = NSTextAlignmentLeft;
        _goodsPriceLB.textColor = RGB(255, 34, 21);
        _goodsPriceLB.text = @"1999TB";
        _goodsPriceLB.font = FontSetWithWeight(18, 0.3f);
    }
    return _goodsPriceLB;
}
//商品来源img
-(UIImageView *)goodsSourceImgV{
    if (!_goodsSourceImgV) {
        _goodsSourceImgV = [[UIImageView alloc] initWithFrame:CGRectMake(self.goodsImgV.right+16, self.goodsImgV.bottom-18, 18, 18)];
        _goodsSourceImgV.image = LoadImage(@"首页_商店图标1");
    }
    return _goodsSourceImgV;
}
//商品来源lb
-(UILabel *)goodsSourceLB{
    if (!_goodsSourceLB) {
        _goodsSourceLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsSourceImgV.right+2, self.goodsSourceImgV.top+1, (ScreenWidth - 80 - 120*Width_Scale), 16)];
        _goodsSourceLB.textAlignment = NSTextAlignmentLeft;
        _goodsSourceLB.textColor = RGB(153, 153, 153);
        _goodsSourceLB.text = @"Apple官方自营旗舰店";
        _goodsSourceLB.font = FontSet(11);
    }
    return _goodsSourceLB;
}



@end
